/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "datasettemplatehierarchy", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"ParentDatasetHierarchyID", "ChildDatasetTemplateID", "RelationshipName"}),
    @UniqueConstraint(columnNames = {"DatasetTemplateHierarchyGlobalID"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatasetTemplateHierarchy.findAll", query = "SELECT d FROM DatasetTemplateHierarchy d"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByDatasetTemplateHierarchyID", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.datasetTemplateHierarchyID = :datasetTemplateHierarchyID"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByParentDatasetHierarchyID", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.parentDatasetHierarchyID = :parentDatasetHierarchyID"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByRelationshipName", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.relationshipName = :relationshipName"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByRelationshipDescription", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.relationshipDescription = :relationshipDescription"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByDatasetTemplateHierarchyGlobalID", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.datasetTemplateHierarchyGlobalID = :datasetTemplateHierarchyGlobalID"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByMinCardinality", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.minCardinality = :minCardinality"),
    @NamedQuery(name = "DatasetTemplateHierarchy.findByMaxCardinality", query = "SELECT d FROM DatasetTemplateHierarchy d WHERE d.maxCardinality = :maxCardinality")})
public class DatasetTemplateHierarchy implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "DatasetTemplateHierarchyID", nullable = false)
    private Integer datasetTemplateHierarchyID;
    @Column(name = "ParentDatasetHierarchyID")
    private Integer parentDatasetHierarchyID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "RelationshipName", nullable = false, length = 45)
    private String relationshipName;
    @Size(max = 256)
    @Column(name = "RelationshipDescription", length = 256)
    private String relationshipDescription;
    @Size(max = 36)
    @Column(name = "DatasetTemplateHierarchyGlobalID", length = 36)
    private String datasetTemplateHierarchyGlobalID;
    @Column(name = "MinCardinality")
    private Integer minCardinality;
    @Column(name = "MaxCardinality")
    private Integer maxCardinality;
    @OneToMany(mappedBy = "referenceDatasetTemplateHierarchyID", fetch = FetchType.LAZY)
    private Collection<DatasetTemplateAssignment> datasetTemplateAssignmentCollection;
    @OneToMany(mappedBy = "parentDatasetTemplateHierarchyID", fetch = FetchType.LAZY)
    private Collection<DatasetInstance> datasetInstanceCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "datasetTemplateHierarchyID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "attributeDatasetTemplateHierarchyID", fetch = FetchType.LAZY)
    private Collection<AssetCategory> assetCategoryCollection;
    @JoinColumn(name = "ChildDatasetTemplateID", referencedColumnName = "DatasetTemplateID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetTemplate childDatasetTemplateID;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "datasetTemplateHierarchy1", fetch = FetchType.LAZY)
    private DatasetTemplateHierarchy datasetTemplateHierarchy;
    @JoinColumn(name = "DatasetTemplateHierarchyID", referencedColumnName = "ParentDatasetHierarchyID", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetTemplateHierarchy datasetTemplateHierarchy1;

    public DatasetTemplateHierarchy() {
    }

    public DatasetTemplateHierarchy(Integer datasetTemplateHierarchyID) {
        this.datasetTemplateHierarchyID = datasetTemplateHierarchyID;
    }

    public DatasetTemplateHierarchy(Integer datasetTemplateHierarchyID, String relationshipName) {
        this.datasetTemplateHierarchyID = datasetTemplateHierarchyID;
        this.relationshipName = relationshipName;
    }

    public Integer getDatasetTemplateHierarchyID() {
        return datasetTemplateHierarchyID;
    }

    public void setDatasetTemplateHierarchyID(Integer datasetTemplateHierarchyID) {
        this.datasetTemplateHierarchyID = datasetTemplateHierarchyID;
    }

    public Integer getParentDatasetHierarchyID() {
        return parentDatasetHierarchyID;
    }

    public void setParentDatasetHierarchyID(Integer parentDatasetHierarchyID) {
        this.parentDatasetHierarchyID = parentDatasetHierarchyID;
    }

    public String getRelationshipName() {
        return relationshipName;
    }

    public void setRelationshipName(String relationshipName) {
        this.relationshipName = relationshipName;
    }

    public String getRelationshipDescription() {
        return relationshipDescription;
    }

    public void setRelationshipDescription(String relationshipDescription) {
        this.relationshipDescription = relationshipDescription;
    }

    public String getDatasetTemplateHierarchyGlobalID() {
        return datasetTemplateHierarchyGlobalID;
    }

    public void setDatasetTemplateHierarchyGlobalID(String datasetTemplateHierarchyGlobalID) {
        this.datasetTemplateHierarchyGlobalID = datasetTemplateHierarchyGlobalID;
    }

    public Integer getMinCardinality() {
        return minCardinality;
    }

    public void setMinCardinality(Integer minCardinality) {
        this.minCardinality = minCardinality;
    }

    public Integer getMaxCardinality() {
        return maxCardinality;
    }

    public void setMaxCardinality(Integer maxCardinality) {
        this.maxCardinality = maxCardinality;
    }

    @XmlTransient
    public Collection<DatasetTemplateAssignment> getDatasetTemplateAssignmentCollection() {
        return datasetTemplateAssignmentCollection;
    }

    public void setDatasetTemplateAssignmentCollection(Collection<DatasetTemplateAssignment> datasetTemplateAssignmentCollection) {
        this.datasetTemplateAssignmentCollection = datasetTemplateAssignmentCollection;
    }

    @XmlTransient
    public Collection<DatasetInstance> getDatasetInstanceCollection() {
        return datasetInstanceCollection;
    }

    public void setDatasetInstanceCollection(Collection<DatasetInstance> datasetInstanceCollection) {
        this.datasetInstanceCollection = datasetInstanceCollection;
    }

    @XmlTransient
    public Collection<DatasetInstanceHierarchy> getDatasetInstanceHierarchyCollection() {
        return datasetInstanceHierarchyCollection;
    }

    public void setDatasetInstanceHierarchyCollection(Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection) {
        this.datasetInstanceHierarchyCollection = datasetInstanceHierarchyCollection;
    }

    @XmlTransient
    public Collection<AssetCategory> getAssetCategoryCollection() {
        return assetCategoryCollection;
    }

    public void setAssetCategoryCollection(Collection<AssetCategory> assetCategoryCollection) {
        this.assetCategoryCollection = assetCategoryCollection;
    }

    public DatasetTemplate getChildDatasetTemplateID() {
        return childDatasetTemplateID;
    }

    public void setChildDatasetTemplateID(DatasetTemplate childDatasetTemplateID) {
        this.childDatasetTemplateID = childDatasetTemplateID;
    }

    public DatasetTemplateHierarchy getDatasetTemplateHierarchy() {
        return datasetTemplateHierarchy;
    }

    public void setDatasetTemplateHierarchy(DatasetTemplateHierarchy datasetTemplateHierarchy) {
        this.datasetTemplateHierarchy = datasetTemplateHierarchy;
    }

    public DatasetTemplateHierarchy getDatasetTemplateHierarchy1() {
        return datasetTemplateHierarchy1;
    }

    public void setDatasetTemplateHierarchy1(DatasetTemplateHierarchy datasetTemplateHierarchy1) {
        this.datasetTemplateHierarchy1 = datasetTemplateHierarchy1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (datasetTemplateHierarchyID != null ? datasetTemplateHierarchyID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetTemplateHierarchy)) {
            return false;
        }
        DatasetTemplateHierarchy other = (DatasetTemplateHierarchy) object;
        if ((this.datasetTemplateHierarchyID == null && other.datasetTemplateHierarchyID != null) || (this.datasetTemplateHierarchyID != null && !this.datasetTemplateHierarchyID.equals(other.datasetTemplateHierarchyID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.DatasetTemplateHierarchy[ datasetTemplateHierarchyID=" + datasetTemplateHierarchyID + " ]";
    }
    
}
